package algorithm;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class AlgoA {
	public static void main(String[] args) {
		nationalDays();
	}

	/**
	 * 第一题
	 */
	static void guessAge() {
		// 根据它的年龄立方数为4位得知
		// 从10岁开始枚举，不超过30
		// 判断不出来，从1遍历到100
		for (int i = 1; i <= 100; i++) {
			if (f(i)) {
				System.out.println(i + " is the answer");
				break;
			}
		}
	}

	// alter + shift + t 批量重命名
	static boolean f(int param) {
		long i_three = (long) param * param * param;
		long i_four = (long) param * param * param * param;
		// 证明立方是四位数&四次方是6位数
		if (i_three / 1000 >= 1 && i_four / 100000 >= 1) {
			String s = (i_three + "").concat(i_four + "");
			// 从1到10进行遍历，如果不包含0~9任意一位数
			// 就返回false，否则返回true
			for (int j = 0; j < 10; j++) {
				if (!s.contains(j + "")) {
					return false;
				}
			}
			return true;
		}
		return false;
	}

	/**
	 * 猜两个孩子的年龄
	 */
	public static void ageForTwoGirls() {
		for (int i = 1; i < 100; i++) {
			for (int j = 2; j <= 100; j++) {
				// 如果i和j的年龄*6=i和j年龄的乘积
				// i和j不是双胞胎
				// i和j相差至少8岁
				if ((i + j) * 6 == (i * j) && i != j && Math.abs(j - i) <= 8) {
					System.out.println("sister 1 age is " + i);
					System.out.println("sister 2 age is " + j);
					return;
				}
			}
		}
	}

	/**
	 * 门牌制作 查询1~2020门牌号总共需要多少个2
	 */
	public static void cardMaking() {
		int searchNum = 2;
		int idx = 1;
		int count = 0;
		while (idx <= 2020) {
			// 判断每一位是否是2
			int temp = idx;
			while (temp != 0) {
				if (temp % 10 == searchNum) {
					count++;
				}
				temp /= 10;
			}
			idx++;
		}
		System.out.println(count + " of '2' are needed to make cards");
	}

	/**
	 * python from datetime import * a=date(1949,10,1) b=date(2012,10,1) res = 0
	 * 
	 * while a <= b: if a.weekday() == 6 and a.month == 10 and a.day == 1: res += 1
	 * a += timedelta(1)
	 * 
	 * print(res)
	 * 
	 */
	static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

	/**
	 * 从建国到现在1949~至今，有几次国庆节正好是周日
	 */
	public static void nationalDays() {
		Calendar calendar = Calendar.getInstance();
		int start = 1949;
		calendar.set(start, 10, 1);
		int count = 0;
		while (start < 2025) {
			if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
				String formatDate = sdf.format(calendar.getTime());
				System.out.println(formatDate);
				count++;
			}
			calendar.set(Calendar.YEAR, ++start);
		}
		System.out.println(count);
	}
}
